package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeadLetterExchangeConfiguration {

    //死信交换机和死信队列
    @Bean
    public DirectExchange deadLetterExchange(){
        return ExchangeBuilder.directExchange("deadLetter.direct").durable(true).build();
    }

    @Bean
    public Queue deadLetterQueue(){
        return QueueBuilder.durable("deadLetter.queue").build();
    }


    @Bean
    public Binding deadLetterBinding(DirectExchange deadLetterExchange,Queue deadLetterQueue){
        return BindingBuilder.bind(deadLetterQueue).to(deadLetterExchange).with("dead");
    }

    //普通队列,没有消费者
    @Bean
    public DirectExchange normalExchange(){
        return ExchangeBuilder.directExchange("normal.direct").build();
    }

    @Bean
    public Queue normalQueue(){//绑定死信交换机
        return QueueBuilder.durable("normal.queue").deadLetterExchange("deadLetter.direct").build();
    }


    @Bean
    public Binding normalBinding(DirectExchange normalExchange,Queue normalQueue){
        return BindingBuilder.bind(normalQueue).to(normalExchange).with("dead");
    }

}
